package com.iplant.mes.controller.andon;

import com.iplant.base.controller.BaseController;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.mes.service.AndonService;
import com.iplant.mes.service.po.andon.AndonProductData;
import com.iplant.mes.service.po.andon.AndonStationStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 工位状态监控控制器
 *
 * @author YouWang·Peng
 * 2024-1-3 10:53:37
 */
@Slf4j
@RestController
@RequestMapping("/api/AndonStationStatus")
public class AndonStationStatusController extends BaseController {

    public AndonStationStatusController() {
        super();
    }

    @Autowired
    AndonService mAndonService;

    /**
     * 查询工位状态监控数据
     */
    @GetMapping("/QueryStationStatusList")
    public Object QueryStationStatusList(HttpServletRequest request) {
        Object wResult = new Object();
        try {
            BMSEmployee wLoginUser = GetSession(request);

            int wOrderID = StringUtils.parseInt(request.getParameter("OrderID"));

            ServiceResult<List<AndonStationStatus>> wServiceResult =
                    mAndonService.Andon_QueryStationStatusList(wLoginUser, wOrderID);

            if (StringUtils.isEmpty(wServiceResult.FaultCode)) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.Result, null);
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.FaultCode);
            }
        } catch (Exception ex) {
            log.error("QueryStationStatusList", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.toString(), null, null);
        }
        return wResult;
    }

    /**
     * 查询生产状态看板数据
     */
    @GetMapping("/QueryAndonProductData")
    public Object QueryAndonProductData(HttpServletRequest request) {
        Object wResult = new Object();
        try {
            BMSEmployee wLoginUser = GetSession(request);

            ServiceResult<AndonProductData> wServiceResult = mAndonService.Andon_QueryProductData(wLoginUser);

            if (StringUtils.isEmpty(wServiceResult.FaultCode)) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", null, wServiceResult.Result);
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.FaultCode);
            }
        } catch (Exception ex) {
            log.error(ex.toString());
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.toString(), null, null);
        }
        return wResult;
    }
}
